<?php
declare (strict_types = 1);

namespace app\admin\controller;

use app\admin\controller\Common;
use think\Request;
use app\admin\model\AuthGroup as MainModel;
use app\admin\model\AuthRule as AuthRuleModel;
use think\facade\View;

class AuthGroup extends Common
{
	public function __construct(){
		parent::__construct();

		$this->model = new MainModel;
		View::assign('model',$this->model);
		View::assign('title',"管理组");
		$this->validate = new \app\admin\validate\AuthGroup;

		/**
		 * 表结构
		 */
		$this->tables = config('tables.auth_group');
		View::assign('tables',$this->tables);
	}
	
	/**
	 * 新增
	 */
    public function create(Request $request)
    {
		$model = new AuthRuleModel();
		//$authlist =	$model->order('class asc')->column("title","id");
		$authlist =	$model->order('class asc')->select()->toArray();
		View::assign('authlist',$authlist);

		return parent::create($request);
    }
	
	/**
	 * 修改
	 */
	public function edit(Request $request){
		$model = new AuthRuleModel();
		//$authlist =	$model->order('class asc')->column("title","id");
		$authlist =	$model->order('class asc')->select()->toArray();
		View::assign('authlist',$authlist);

		$re = $this->update($request);
		if(!empty($re)){
			return $re;
		}

		$id = intval(input('param.id'));
		$info = $this->model->find($id);

		return view('edit',[
			'info'=>$info
		]);	
	}
}
